package com.demo.consumer.condition;


import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.type.AnnotatedTypeMetadata;


public class OnPropertyContainsCondition implements Condition {



    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata){

        String value = (String) metadata.getAnnotationAttributes(ConditionalOnContainsProperty.class.getName()).get("value");
        ConfigurableEnvironment env = context.getBeanFactory().getBean(ConfigurableEnvironment.class);
        MutablePropertySources propertySources = env.getPropertySources();
        return context.getEnvironment().containsProperty(value);


    }
}
